//index.js
//获取应用实例
const app = getApp()
 const Api = require("../../utils/api.js").API
 const Store = require("../../utils/store.js").store
  const codeZ = require("../../utils/util.js")
Page({
  data: {
  
  list:[],
  total:0,
  page:1,
 
       
   
  },
  
 
  onShow(){
      
      this.setData({
          list:[]
      })
      this.requstList(1);
     

  },
  clickHome:function(){
      wx.switchTab({
          url:'../GoodsList/index'
      })
  },
  goShop:function(e){
        let i = e.currentTarget.dataset.item;
    
  
      wx.navigateTo({
               url: '../../pages/shouliren/index',
                 success: function(res) {
                   // 通过eventChannel向被打开页面传送数据
                   res.eventChannel.emit('acceptDataFromOpenerPage', { data:i })
                 }
         })
           
   
      
  },
  requstList:function(page){
    
     let that = this;
     
    var  data={
                  "asc": true,
                  "goodsName": "",
                  "limit": 10,
                  "page": page,
                  "sidx": "",
                  "skuNo": "",
                  "spuNo": ""                                     
                } 
                
      
   
      Api.cheakSCApi(data).then(res=>{
          console.log(res);
          if(res.code == 0){
              var arr =  res.page.records;           
               
                if (arr.length == 0) {
                    return;
                }
            
              var oldArr = that.data.list;
                           
              var newArr = oldArr.concat(arr); 
            
              that.setData({
                  list:newArr,
                  total:res.page.total,
                  
              })   
          }else if(res.code == "401"){
              that.setData({
                  isShow:true,    
              })   
              
          }else{
              
          }
      
      })
  },
    
  refreshBottom:function(e){
       //  var i = e.currentTarget.dataset.index;
       // // let list = `tabsArray[${i}].list`;
       
     
        var total = this.data.total;
        var list = this.data.list;
            
        if(list.length <total){
            var a = this.data.page;     
            a++;
            this.setData({
                page: a
            }) 
             this.requstList(a)
            
        }
                  
      
  }
  
  
  
  

   
  


  
})
